const CompressionWebpackPlugin = require('compression-webpack-plugin');
module.exports = {
	//设置为空打包后不分更目录还是多级目录
	publicPath: "./",
	//build编译后存放静态文件的目录
	//assetsDir: "static",

	// build编译后不生成资源MAP文件
	productionSourceMap: false,

	//开发服务,build后的生产模式还需nginx代理
	devServer: {
		open: false, //运行后自动打开浏览器
		port: 2800, //挂载端口
		// proxy:'http://47.94.22.162:3085'
	},

	chainWebpack: (config) => {
		// config.module
		// 	.rule("images")
		// 	.use("image-webpack-loader")
		// 	.loader("image-webpack-loader")
		// 	.options({
		// 		bypassOnDebug: true,
		// 	})
		// 	.end();

		config.externals({
			vue: "Vue",
			axios: "axios",
			echarts: "echarts",
			"vue-router": "VueRouter",
			tinymce: "tinymce",
			"element-plus": "ElementPlus",
			xlsx: "XLSX",
		});
		// 移除 prefetch 插件
		config.plugins.delete("preload");
		config.plugins.delete("prefetch");
		config.resolve.alias.set("vue-i18n", "vue-i18n/dist/vue-i18n.cjs.js");
	},

	configureWebpack: (config) => {
		if (process.env.NODE_ENV === 'production') {
            config.plugins.push(
                ...[
                    new CompressionWebpackPlugin({
                        filename: '[path].gz[query]',
                        algorithm: 'gzip',
                        test: /\.(js|css|html)$/i,
                        threshold: 2048,
                        minRatio: 0.8
                    })
                ]
            );
        }
		//性能提示
		config.performance = {
			hints: false,
		};
		config.optimization = {
			splitChunks: {
				chunks: "all",
				automaticNameDelimiter: "~",
				name: true,
				cacheGroups: {
					//第三方库抽离
					vendor: {
						name: "modules",
						test: /[\\/]node_modules[\\/]/,
						priority: -10,
					},
					elicons: {
						name: "elicons",
						test: /[\\/]node_modules[\\/]@element-plus[\\/]icons[\\/]/,
					},
					tinymce: {
						name: "tinymce",
						test: /[\\/]node_modules[\\/]tinymce[\\/]/,
					},
					echarts: {
						name: "echarts",
						test: /[\\/]node_modules[\\/]echarts[\\/]/,
					},
					xgplayer: {
						name: "xgplayer",
						test: /[\\/]node_modules[\\/]xgplayer.*[\\/]/,
					},
				},
			},
		};
	},
};
